<!DOCTYPE html>
<html lang="en">
<head>
		<title>Snippets &mdash; Articles tagged web-server</title>
		<meta charset="utf-8" />
		<link rel="profile" href="http://gmpg.org/xfn/11" />
		<link rel="stylesheet" type="text/css" href="https://corteousquestions.club/theme/css/style.css" />
		<link rel='stylesheet' id='oswald-css'  href='http://fonts.googleapis.com/css?family=Oswald&#038;ver=3.3.2' type='text/css' media='all' />
		<style type="text/css">
			body.custom-background { background-color: #f5f5f5; }
		</style>
		<link rel="alternate" type="application/atom+xml"
			title="Snippets — Flux Atom"
			href="https://corteousquestions.club/" /> 
		<!--[if lte IE 8]><script src="https://corteousquestions.club/theme/js/html5shiv.js"></script><![endif]-->
</head>

<body class="home blog custom-background " >
	<div id="container">
		<div id="header">
				<h1 id="site-title"><a href="https://corteousquestions.club">Snippets</a></h1>
<h2 id="site-description">All that I will forget is here</h2>		</div><!-- /#banner -->
		
		<div id="menu">
			<div class="menu-navigation-container">
				<ul id="menu-navigation" class="menu">
						<li class="menu-item menu-item-type-post_type menu-item-object-page"><a href="https://corteousquestions.club/category/misc.html">misc</a></li>

				</ul>
			</div> <!--/#menu-navigation-container-->
		</div><!-- /#menu -->
		
		<div class="page-title">
<div class="page-title">
	<h2>Tagged with <span>web-server</span> &hellip;</h2>
</div>
		</div>
	
		<div id="contents">
<div class="post type-post status-publish format-standard hentry category-general" id="post">
	<div class="entry-meta">
		<div class="date"><a href="https://corteousquestions.club/setting-up-nginx-server.html">Sat 17 April 2021</a></div>
		<span class="byline">By <a href="https://corteousquestions.club/author/mclds.html">mclds</a></span>
			<span class="cat-links"><a href="https://corteousquestions.club/category/misc.html" title="View all posts in misc" rel="category tag">misc</a></span>
	</div> <!-- /#entry-meta -->
	<div class="main">
		<h2 class="entry-title">
			<a href="https://corteousquestions.club/setting-up-nginx-server.html" title="Permalink to Setting up nginx server" rel="bookmark">Setting up nginx server</a>
		</h2>
		<div class="entry-content">
			<p>I'm trying out the Nginx web server instead of Apache because<br>
   I've been hearing a lot about how much easier it is to<br>
   configure, and that it's faster etc, etc. I can now say with<br>
   authority, that is not easier to configure, it's harder, but<br>
   it's a good harder, because makes you have more control about<br>
   what you're setting up. So, I'll leave here the server block<br>
   (Nginx version of Virtual Hosts), I made in 28/01/21, for a<br>
   a blog called 'Dazed and Confused':  </p>
<hr>
<p># server {<br>
          # Notice that, unlike Apache, you can't have the same<br>
          # port for IPV4 and IPV6. So you'll have to comment it<br>
          # out. <br>
          listen 443 ssl;<br>
          # listen [::]: 443 ssl;  </p>
<div class="highlight"><pre><span></span><code>      <span class="nt">root</span> <span class="o">/</span><span class="nt">var</span><span class="o">/</span><span class="nt">www</span><span class="o">/</span><span class="nt">constantconstipation</span><span class="p">.</span><span class="nc">club</span><span class="o">/</span><span class="nt">html</span><span class="o">/</span><span class="nt">public</span><span class="o">/;</span>  
      <span class="err">#</span> <span class="nt">Nginx</span> <span class="nt">serves</span> <span class="nt">what</span> <span class="nt">is</span> <span class="nt">described</span> <span class="nt">in</span> <span class="nt">the</span> <span class="nt">index</span> <span class="nt">files</span> <span class="nt">it</span>  
      <span class="err">#</span> <span class="nt">finds</span> <span class="nt">on</span> <span class="nt">the</span> <span class="nt">pages</span><span class="o">.</span>  
      <span class="nt">index</span> <span class="nt">index</span><span class="p">.</span><span class="nc">html</span> <span class="nt">index</span><span class="p">.</span><span class="nc">htm</span> <span class="nt">index</span><span class="p">.</span><span class="nc">nginx-debian</span><span class="p">.</span><span class="nc">html</span><span class="o">;</span>

      <span class="nt">server_name</span> <span class="nt">constantconstipation</span><span class="p">.</span><span class="nc">club</span> <span class="nt">www</span><span class="p">.</span><span class="nc">constantconstipation</span><span class="p">.</span><span class="nc">club</span><span class="o">;</span>

      <span class="nt">location</span> <span class="o">/</span> <span class="p">{</span>  
              <span class="err">try_files</span> <span class="err">$uri</span> <span class="err">$uri/</span> <span class="err">=404</span><span class="p">;</span>  
      <span class="p">}</span>  
      <span class="err">#</span> <span class="nt">Nginx</span> <span class="nt">wasn</span><span class="s1">&#39;t finding the blog folder content, nor it&#39;</span><span class="nt">s</span>  
      <span class="err">#</span> <span class="nt">css</span> <span class="nt">structure</span><span class="o">.</span> <span class="nt">So</span> <span class="nt">I</span> <span class="nt">inserted</span> <span class="nt">the</span> <span class="s1">&#39;try_files&#39;</span><span class="o">,</span> <span class="nt">and</span> <span class="nt">it</span>  
      <span class="err">#</span> <span class="nt">worked</span><span class="o">.</span> <span class="nt">The</span> <span class="nt">line</span><span class="s1">&#39;s meaning is this:  </span>
<span class="s1">      # &#39;</span><span class="nt">Checks</span> <span class="nt">the</span> <span class="nt">existence</span> <span class="nt">of</span> <span class="nt">files</span> <span class="nt">in</span> <span class="nt">the</span> <span class="nt">specified</span> <span class="nt">order</span>  
      <span class="err">#</span> <span class="nt">and</span> <span class="nt">uses</span> <span class="nt">the</span> <span class="nt">first</span> <span class="nt">found</span> <span class="nt">file</span> <span class="nt">for</span> <span class="nt">request</span> <span class="nt">processing</span><span class="o">;</span>  
      <span class="err">#</span> <span class="nt">the</span> <span class="nt">processing</span> <span class="nt">is</span> <span class="nt">performed</span> <span class="nt">in</span> <span class="nt">the</span> <span class="nt">current</span> <span class="nt">context</span><span class="o">.</span>  
      <span class="err">#</span> <span class="cp">[</span><span class="nx">...</span><span class="cp">]</span>  
      <span class="err">#</span> <span class="nt">If</span> <span class="nt">none</span> <span class="nt">of</span> <span class="nt">the</span> <span class="nt">files</span> <span class="nt">were</span> <span class="nt">found</span><span class="o">,</span> <span class="nt">an</span> <span class="nt">internal</span> <span class="nt">redirect</span>  
      <span class="err">#</span> <span class="nt">to</span> <span class="nt">the</span> <span class="nt">uri</span> <span class="nt">specified</span> <span class="nt">in</span> <span class="nt">the</span> <span class="nt">last</span> <span class="nt">parameter</span> <span class="nt">is</span> <span class="nt">made</span><span class="o">.</span><span class="s1">&#39;  </span>
<span class="s1">      location /blogs/ {  </span>
<span class="s1">              try_files $uri $uri/ =404;  </span>
<span class="s1">      }</span>

<span class="s1">      # This is what is requested for ssl connection. Mind you,  </span>
<span class="s1">      # this configuration is being used because, I already had  </span>
<span class="s1">      # the certbot certificate and needed to change it from an  </span>
<span class="s1">      # Apache server to Nginx. Probably if you download a  </span>
<span class="s1">      # certbot version for Nginx, it will do all this  </span>
<span class="s1">      # configuration for you. But if it doesn&#39;</span><span class="nt">t</span><span class="o">,</span> <span class="nt">you</span> <span class="nt">can</span>  
      <span class="err">#</span> <span class="nt">copy</span><span class="o">/</span><span class="nt">paste</span> <span class="nt">from</span> <span class="nt">the</span> <span class="nt">third</span> <span class="nt">row</span> <span class="nt">onward</span> <span class="nt">and</span> <span class="nt">it</span> <span class="nt">will</span> <span class="nt">run</span><span class="o">.</span>  
      <span class="err">#</span> <span class="nt">NOTE</span><span class="o">:</span> <span class="nt">in</span> <span class="nt">the</span> <span class="nt">last</span> <span class="nt">field</span><span class="o">,</span> <span class="s1">&#39;XSS-Protection&#39;</span><span class="o">,</span> <span class="nt">I</span> <span class="nt">had</span> <span class="nt">to</span> <span class="nt">change</span>  
      <span class="err">#</span> <span class="nt">the</span> <span class="nt">double</span> <span class="nt">quotes</span> <span class="nt">that</span> <span class="nt">were</span> <span class="nt">to</span> <span class="nt">apostrophes</span><span class="o">,</span> <span class="nt">or</span> <span class="nt">mysql</span> <span class="nt">would</span>  
      <span class="err">#</span> <span class="nt">respond</span> <span class="nt">with</span> <span class="nt">an</span> <span class="nt">error</span><span class="o">.</span> <span class="nt">If</span> <span class="nt">you</span> <span class="nt">have</span> <span class="nt">any</span> <span class="nt">problems</span><span class="o">,</span> <span class="nt">just</span> <span class="nt">put</span>  
      <span class="err">#</span> <span class="nt">double</span> <span class="nt">quotes</span> <span class="nt">in</span> <span class="nt">it</span><span class="o">.</span>  
      <span class="nt">ssl_certificate</span>     <span class="o">/</span><span class="nt">etc</span><span class="o">/</span><span class="nt">letsencrypt</span><span class="o">/</span><span class="nt">live</span><span class="o">/</span><span class="nt">constantconstipation</span><span class="p">.</span><span class="nc">club</span><span class="o">/</span><span class="nt">fullchain</span><span class="p">.</span><span class="nc">pem</span><span class="o">;</span>  
      <span class="nt">ssl_certificate_key</span> <span class="o">/</span><span class="nt">etc</span><span class="o">/</span><span class="nt">letsencrypt</span><span class="o">/</span><span class="nt">live</span><span class="o">/</span><span class="nt">constantconstipation</span><span class="p">.</span><span class="nc">club</span><span class="o">/</span><span class="nt">privkey</span><span class="p">.</span><span class="nc">pem</span><span class="o">;</span>  
      <span class="nt">ssl_protocols</span> <span class="nt">TLSv1</span><span class="p">.</span><span class="nc">2</span><span class="o">;</span>  
      <span class="nt">ssl_prefer_server_ciphers</span> <span class="nt">on</span><span class="o">;</span>  
      <span class="nt">ssl_ciphers</span> <span class="nt">ECDHE-RSA-AES256-GCM-SHA512</span><span class="p">:</span><span class="nd">DHE-RSA-AES256-GCM-SHA512</span><span class="p">:</span><span class="nd">ECDHE-RSA-AES256-GCM-SHA384</span><span class="p">:</span><span class="nd">DHE-RSA-AES256-GCM-SHA384</span><span class="p">:</span><span class="nd">ECDHE-RSA-AES256-SHA384</span><span class="o">;</span>  
      <span class="nt">ssl_ecdh_curve</span> <span class="nt">secp384r1</span><span class="o">;</span> <span class="err">#</span> <span class="nt">Requires</span> <span class="nt">nginx</span> <span class="o">&gt;=</span> <span class="nt">1</span><span class="p">.</span><span class="nc">1</span><span class="p">.</span><span class="nc">0</span>  
      <span class="nt">ssl_session_timeout</span>  <span class="nt">10m</span><span class="o">;</span>  
      <span class="nt">ssl_session_cache</span> <span class="nt">shared</span><span class="p">:</span><span class="nd">SSL</span><span class="p">:</span><span class="nd">10m</span><span class="o">;</span>  
      <span class="nt">ssl_session_tickets</span> <span class="nt">off</span><span class="o">;</span> <span class="err">#</span> <span class="nt">Requires</span> <span class="nt">nginx</span> <span class="o">&gt;=</span> <span class="nt">1</span><span class="p">.</span><span class="nc">5</span><span class="p">.</span><span class="nc">9</span>  
      <span class="nt">ssl_stapling</span> <span class="nt">on</span><span class="o">;</span> <span class="err">#</span> <span class="nt">Requires</span> <span class="nt">nginx</span> <span class="o">&gt;=</span> <span class="nt">1</span><span class="p">.</span><span class="nc">3</span><span class="p">.</span><span class="nc">7</span>  
      <span class="nt">ssl_stapling_verify</span> <span class="nt">on</span><span class="o">;</span> <span class="err">#</span> <span class="nt">Requires</span> <span class="nt">nginx</span> <span class="o">=&gt;</span> <span class="nt">1</span><span class="p">.</span><span class="nc">3</span><span class="p">.</span><span class="nc">7</span>  
      <span class="nt">resolver</span> <span class="nt">8</span><span class="p">.</span><span class="nc">8</span><span class="p">.</span><span class="nc">8</span><span class="p">.</span><span class="nc">8</span> <span class="nt">8</span><span class="p">.</span><span class="nc">8</span><span class="p">.</span><span class="nc">4</span><span class="p">.</span><span class="nc">4</span> <span class="nt">valid</span><span class="o">=</span><span class="nt">300s</span><span class="o">;</span>  
      <span class="nt">resolver_timeout</span> <span class="nt">5s</span><span class="o">;</span>  
      <span class="nt">add_header</span> <span class="nt">X-Frame-Options</span> <span class="nt">DENY</span><span class="o">;</span>  
      <span class="nt">add_header</span> <span class="nt">X-Content-Type-Options</span> <span class="nt">nosniff</span><span class="o">;</span>  
      <span class="nt">add_header</span> <span class="nt">X-XSS-Protection</span> <span class="s1">&#39;1; mode=block&#39;</span><span class="o">;</span>
</code></pre></div>


<p>}  </p>
<hr>
<p>The whole process: https://do.co/3t7zmIr  </p>
		</div> <!--/#entry-content-->
    		<span class="tag-links"><strong>Tagged</strong>
 <a href="https://corteousquestions.club/tag/apache.html" rel="tag">apache</a>,  <a href="https://corteousquestions.club/tag/nginx.html" rel="tag">nginx</a>,  <a href="https://corteousquestions.club/tag/web-server.html" rel="tag">web-server</a>    		</span>
	</div> <!--/#main-->
</div>  <!--/#post-->		</div>
		
		<div id="footer">
			<p>Powered by <a href="http://getpelican.com">Pelican</a>, theme by <a href="http://bunnyman.info">tBunnyMan</a>.</p>
		</div><!-- /#footer -->
	</div><!-- /#container -->
	<div style="display:none"></div>
</body>
</html>